/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.cvut.fel.taskpro.data.entity;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.Temporal;


/**
 * This entity represent version of submit task. Each must contains files.
 * @author Tom
 * @version 1.0.0 beta
 */
@Entity
@Table(name="version")
public class Version implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    @OneToMany(mappedBy = "version", fetch = FetchType.LAZY, cascade = {CascadeType.REFRESH, CascadeType.DETACH, CascadeType.MERGE, CascadeType.PERSIST})
    @OrderBy("version ASC")
    private List<VersionFile> mVersionFiles;
    @ManyToOne(fetch= FetchType.LAZY,cascade= CascadeType.ALL)
    private AssignmentSubmit assignmentSubmit;
    @Temporal(javax.persistence.TemporalType.TIMESTAMP)
    private Date dateOfSubmit;
    @ManyToOne(fetch = FetchType.LAZY, cascade = {CascadeType.REFRESH, CascadeType.DETACH, CascadeType.MERGE, CascadeType.PERSIST})
    private Student submittedStudent;
    private int numberOfVersion;
 
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }
    
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Version)) {
            return false;
        }
        Version other = (Version) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "cz.cvut.fel.taskpro.data.entity.Version[ id=" + id + " ]";
    }

    public Date getDateOfSubmit() {
        return dateOfSubmit;
    }

    public void setDateOfSubmit(Date dateOfSubmit) {
        this.dateOfSubmit = dateOfSubmit;
    }

    public AssignmentSubmit getAssignmentSubmit() {
        return assignmentSubmit;
    }

    public void setAssignmentSubmit(AssignmentSubmit assignmentSubmit) {
        this.assignmentSubmit = assignmentSubmit;
    }

    public List<VersionFile> getmVersionFiles() {
        return mVersionFiles;
    }

    public void setmVersionFiles(List<VersionFile> mVersionFiles) {
        this.mVersionFiles = mVersionFiles;
    }

    public Version() {
    }

    public Version(AssignmentSubmit assignmentSubmit) {
        this.assignmentSubmit = assignmentSubmit;
    }

    public int getNumberOfVersion() {
        return numberOfVersion;
    }

    public void setNumberOfVersion(int numberOfVersion) {
        this.numberOfVersion = numberOfVersion;
    }

    public Student getSubmittedStudent() {
        return submittedStudent;
    }

    public void setSubmittedStudent(Student submittedStudent) {
        this.submittedStudent = submittedStudent;
    }

   

   

   
    
}
